package com.freewater.springboot.demo.spel.constructor;

import com.freewater.springboot.demo.spel.Inventor;
import com.freewater.springboot.demo.spel.Society;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

public class Main {
    public static void main(String[] args) {
        ExpressionParser parser = new SpelExpressionParser();
        final Inventor inventor = parser.parseExpression("new com.freewater.springboot.demo.spel.Inventor('Albert Einstein', 'German')").getValue(Inventor.class);
        assert inventor != null;
        System.out.println(inventor.getName());

        Society society = new Society();
        parser.parseExpression("Members.add(new com.freewater.springboot.demo.spel.Inventor('Albert Einstein', 'German'))").getValue(society);
        System.out.println(society.getMembers().getFirst().getName());
    }
}
